package com.attendance.service.impl;

import com.attendance.common.CommonPage;
import com.attendance.common.CommonResult;
import com.attendance.mapper.CourseMapper;
import com.attendance.pojo.Course;
import com.attendance.pojo.Pages;
import com.attendance.service.CourseService;
import com.attendance.vo.CourseVO;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    //查询所有课程
    @Override
    public CommonResult selectAllCourse(Pages pages) {
        PageHelper.startPage(pages.getPage(), pages.getNum());
        return CommonResult.success(CommonPage.restPage(courseMapper.selectAllCourse()));
    }

    //根据条件查询课程
    @Override
    public CommonResult selectCourse(CourseVO courseVO, Pages pages) {
        PageHelper.startPage(pages.getPage(),pages.getNum());
        return CommonResult.success(CommonPage.restPage(courseMapper.selectCourse(courseVO)));
    }

    //新增课程
    @Override
    public CommonResult addCourse(Course course) {
        int i = courseMapper.addCourse(course);
        if(i==1){
            return CommonResult.success("插入成功!");
        }else{
            return CommonResult.failed("插入失败");
        }
    }

    //更新课程信息
    @Override
    public CommonResult updateCourse(Course course) {
        int i = courseMapper.updateCourse(course);
        if(i==1){
            return CommonResult.success("更新成功!");
        }else{
            return CommonResult.failed("更新失败!");
        }
    }

    //修改课程状态
    @Override
    public CommonResult modifyCourse(Course course) {
        int i = courseMapper.modifyCourse(course);
        if(i==1){
            return CommonResult.success("删除成功!");
        }else{
            return CommonResult.failed("删除失败!");
        }
    }

    //课程下拉框接口(所有课程信息)
    @Override
    public CommonResult queryCourse() {
        return CommonResult.success(courseMapper.queryCourse());
    }

    //通过教师id查询课程的下拉框接口
    @Override
    public CommonResult queryCourseByteaId(int teaId) {
        return CommonResult.success(courseMapper.queryCourseByteaId(teaId));
    }

    //通过班级id查询课程的下拉框接口
    @Override
    public CommonResult queryCourseByclassId(int classId) {
        return CommonResult.success(courseMapper.queryCourseByclassId(classId));
    }

}
